<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

	<link rel="stylesheet" href="./Tpl/css/bootstrap.min.css">
  <script type="text/javascript" src="./Tpl/js/jquery-3.1.1.min.js"></script>
	<style type="text/css">
/*	div{
		border: 1px solid red;
	}*/
  .ssl{

  }
  .center-block{
    font-size: 24px;
    font-weight: 200;
    text-align: center;
  }
  .btn-lg{
   float: right;
   margin-left: 10px;
   font-size: 14px;
  }
	.foot,.main{
		margin-top: 10px;
	}
	.col-md-12 .foot{
		width: 100%;
		height: 130px;
	}
  h2{
    text-align: center;
    background: #fff url() 0 0 no-repeat;
  }
  li{
    list-style: none;
    float: right;
  }
	</style>
	<title>留言板</title>
</head>
<body>
<div class="col-md-12">
	<ul class="nav nav-pills nn">
  <li role="presentation" class="active"><a href="#">留言板</a></li>
  <li role="presentation"><a href="#">home</a></li>
  <li role="presentation"><a href="./Tpl/register.html">没账号请点击注册</a></li>
  <?php session_start() ?>
  <?php if (isset($_SESSION['username'])) { ?>
     <a href="./clear.php"><button type="button" class="btn btn-warning">退出登录</button></a><h2 class="bg-info">欢迎<?php echo $_SESSION['nikename'] ?>来到呵呵哒论坛</h2>
  <?php }else{ ?>  
  <a href="./Tpl/login.html"><button type="button" class="btn btn-info">点击登录</button></a> 
   <?php } ?>
<!-- $color[array_rand($color)] -->
</ul>
</div>
<div class="col-md-12 main">
   		<?php foreach ($db as $k => $v) {?>
   		<div class="alert alert-success msgRow" role="alert">
      
   			 <strong calss="ssl">用户名：<?php echo $v['username'] ?></strong> 
         <div class="center-block alert-info">
   			 <?php echo $v['content'] ?></div>发布时间:<?php echo date('Y-m-d H:i:s',$v['create_time']) ?>
         <?php if (@$_SESSION['nikename']==$v['username']) { ?>
   			<!--  <a href="./del.php?id=<?php echo $k ?>" onclick="return confirm('确定删除吗?');"> -->
        <li>
        <button type="button" class="btn btn-lg btn-danger adel"  id="<?php echo $k; ?>" >
          <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
          <span class="glyphicon-class">删除</span>
        </button>
        </li>
   			 <a href="./edit.php?id=<?php echo $k ?>">
          <button type="button" class="btn btn-lg alert-warning">
         <li class="alert-warning">
          <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
          <span class="glyphicon-class">修改</span>
        </li>
          </button>
        </a>
   		<?php } ?>
      </div>
   		<?php } ?>
     
      
</div>
<div class="col-md-12">
<form class="form-inline" method="post" action="./add.php">
	<div class="col-md-12">
		
  <div class="form-group">
    <label class="sr-only" for="exampleInputAmount">用户名 (in dollars)</label>
    <div class="input-group">
      <div class="input-group-addon">用户名:</div>
      <input class="form-control" id="disabledInput" type="text" name="username" placeholder="<?php echo isset($_SESSION['nikename'])?$_SESSION['nikename']:''; ?>" value="<?php echo isset($_SESSION['nikename'])?$_SESSION['nikename']:''; ?>" disabled>
      <input type="hidden" name="username" value="<?php echo isset($_SESSION['nikename'])?$_SESSION['nikename']:''; ?>" >
      <div class="input-group-addon">欢迎留言</div>
    </div>
  </div>
  <?php if (isset($_SESSION['username'])) { ?>
  <button type="submit" class="btn btn-primary">提交留言</button>
  <?php }else{ ?>
      <a href="./Tpl/login.html"><button type="button" class="btn btn-info">发言请先登录登录</button></a> 
  <?php } ?>
	<div class="col-md-12"><textarea class="form-control foot" rows="3" name="content"></textarea></div>
	</form>
<nav aria-label="Page navigation">
  <ul class="pagination">
  	<?php if ($page<>1) {?>
  		   <li>
      <a href="./index.php?p=<?php echo $page-1 ?>" aria-label="Previous">
        <span aria-hidden="true">上一页;</span>
      </a>
    </li>
  	<?php } ?>
    
    <?php for ($i=$pages; $i >=1 ; $i--) { ?>
    	<li><a href="./index.php?p=<?php echo $i ?>"><?php echo $i ?></a></li>
  	<?php } ?>
      	<?php if ($page<>$pages) {?>
  		   <li>
      <a href="./index.php?p=<?php echo $page+1 ?>" aria-label="Previous">
        <span aria-hidden="true">下一页</span>
      </a>
    </li>
  	<?php } ?>
  </ul>
</nav>
</div>
  <script type="text/javascript">
  $(function  () {
      $('.adel').click(function(event) {
          var id = $(this).attr('id');
          adel = $(this);
          $.ajax({
            url: './adel.php',
            type: 'post',
            dataType: 'json',
            data: {Msg: id},
          })
          .done(function(data) {
           if (data.error==0) {
              alert(data.info);
              adel.parents('.msgRow').remove();
           };
          })
          .fail(function() {
            alert('删除失败');
          })
        
      });
  })

  </script>
</body>
</html>